﻿using DonNicky.Common;
using NUnit.Framework;
using TestCases.Resources;

namespace TestCases
{
    [TestFixture]
    public class TypeExtensionsTests
    {
        [Test]
        public void GetDisplayName()
        {
            Assert.AreEqual("ClassWithoutDisplayNameAttribute",
                            typeof(ClassWithoutDisplayNameAttribute).GetDisplayName());
            Assert.AreEqual("DisplayName", typeof(ClassWithDisplayNameAttribute).GetDisplayName());
            Assert.AreEqual("ResourceDisplayName", typeof(ClassWithDisplayNameAttributeFromResource).GetDisplayName());
            Assert.AreEqual("ResourceDisplayName", typeof(ClassWithInheritedDisplayNameAttributeFromResource).GetDisplayName());
            Assert.AreEqual("DisplayName", typeof(InterfaceWithDisplayNameAttribute).GetDisplayName());
            Assert.AreEqual("DisplayName", typeof(ClassWithInheritedDisplayNameAttribute).GetDisplayName());
        }

        [Test]
        public void GetPluralDisplayName()
        {
            Assert.AreEqual("ClassWithoutDisplayNameAttribute",
                            typeof(ClassWithoutDisplayNameAttribute).GetPluralDisplayName());
            Assert.AreEqual("PluralDisplayName", typeof(ClassWithDisplayNameAttribute).GetPluralDisplayName());
            Assert.AreEqual("ResourceDisplayNamePlural", typeof(ClassWithDisplayNameAttributeFromResource).GetPluralDisplayName());
            Assert.AreEqual("ResourceDisplayNamePlural", typeof(ClassWithInheritedDisplayNameAttributeFromResource).GetPluralDisplayName());
            Assert.AreEqual("PluralDisplayName", typeof(InterfaceWithDisplayNameAttribute).GetPluralDisplayName());
            Assert.AreEqual("PluralDisplayName", typeof(ClassWithInheritedDisplayNameAttribute).GetPluralDisplayName());
        }
    }

    public class ClassWithoutDisplayNameAttribute
    { }

    [TypeDisplayName(Name = "DisplayName", PluralName = "PluralDisplayName")]
    public class ClassWithDisplayNameAttribute
    { }

    [TypeDisplayName(ResourceType = typeof(Strings), Name = "ClassDisplayName", PluralName = "ClassDisplayNamePlural")]
    public class ClassWithDisplayNameAttributeFromResource
    { }

    public class ClassWithInheritedDisplayNameAttributeFromResource : ClassWithDisplayNameAttributeFromResource
    { }

    [TypeDisplayName(Name = "DisplayName", PluralName = "PluralDisplayName")]
    // ReSharper disable InconsistentNaming
    public interface InterfaceWithDisplayNameAttribute
    // ReSharper restore InconsistentNaming
    { }

    public class ClassWithInheritedDisplayNameAttribute : InterfaceWithDisplayNameAttribute
    { }
}
